// Problem 041: Pandigital prime
// We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
// What is the largest n-digit pandigital prime that exists?
// --------
// 123,12345,123456 can be divided by 3, so find the prime upon 1234567

package main

import (
	"fmt"
	"projecteuler/euler"
	"strconv"
)

func p041() {
	var ans int
	for p := 7654321; p > 1000000; p -= 2 {
		if !euler.IsPrime(p) {
			continue
		}
		if euler.IsUniqueDigits(strconv.Itoa(p*1000 + 890)) {
			ans = p
			break
		}
	}
	fmt.Println("Problem 041:", ans)
}
